function calculate() {
    // 获取输入框的值
    let sn1 = document.getElementById('num1').value;
    let sn2 = document.getElementById('num2').value;
    let num1 = parseFloat(sn1);
    let num2 = parseFloat(sn2);


    if (sn1 + sn2 == "") { // 检测空
        document.getElementById('result').innerHTML = ``; return;
    }
    if (isNaN(num1) || isNaN(num2)) { //是否无法读取
        alert("请输入整数种子!"); return;
    }
    if (String(num1) != sn1 || String(num2) != sn2) { //是否无法还原
        alert("请输入整数种子!"); return;
    }
    else if (parseInt(num1) != num1 || parseInt(num2) != num2) { //是否是浮点数
        alert("请输入整数种子!"); return;
    }

    // 取绝对值
    [num1, num2] = [Math.abs(num1), Math.abs(num2)]

    // 检测顺序
    if (num1 < num2) {
        [num1, num2] = [num2, num1];
    }
    
    // 计算勾股数
    const a = num1**2 - num2**2;
    const b = 2 * num1 * num2;
    const c = num1**2 + num2**2;
    
    // 显示结果
    document.getElementById('result').innerHTML = a + `² + ` + b + `² = ` + c + `²`;
}

// Enter键计算
document.onkeydown = function(event) {
    if (event.key == "Enter") {
        calculate();
    }
};